﻿using System;
using System.Web.Mvc;
using System.Web.Routing;

namespace FBGraph.Web.Mvc
{
    /// <summary>Provides base controller functionality for MVC applications utilizing the Graph API.</summary>
    public abstract class FBGraphMvcController : Controller
    {
        /// <summary>Gets an instance of a <see cref="FBGraphContext" /> for the current request.</summary>
        protected internal FBGraphHttpContext FbContext { get; private set; }

        /// <summary>Initializes the controller's <see cref="FBGraphHttpContext" />.</summary>
        /// <param name="requestContext">The request context.</param>
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);

            // This must be done here rather than in the constructor so that HttpContext is available.
            this.FbContext = FBGraphHttpContext.Current(this.HttpContext);
        }
    }
}